// pages/place/place.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		logs: '',
		http: getApp().globalData.map,
		state: 1,
		value:['','请选择门店'],
		itm:0,
		sure:0,
		jifen:0,
		pd:'',
		ewyf:0,
		add:'',
		uid:'',
		lit:'',
		list:'',
		qid:'',
		txt:'',
		qian:0,
		yunfei:0,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(res) {
		console.log(res)
		this.setData({
			ccname:res.name,
			ccspid:res.spid,
			ccnum:res.num,
			num: res,
		})
	},
	yunxin(){
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				wx.request({
					url: getApp().globalData.http+"action=shopBuyNow&goodid=" + this.data.ccname + "&userid=" + e.data.uid +
						"&spid="+this.data.ccspid,
					success: (t) => {
						let yuanjia=t.data.data.Fee
						console.log(this.data.add)
						if(this.data.add==''){
							this.setData({
							add: t.data.data.addr,
							})
						}
						if(this.data.add.Prov=='内蒙古自治区'||this.data.add.Prov=='西藏自治区'||this.data.add.Prov=='青海省'||this.data.add.Prov=='宁夏回族自治区'||this.data.add.Prov=='新疆维吾尔自治区'){
								t.data.data.Fee+=20
						}else{
							t.data.data.Fee=yuanjia
							this.setData({
								ewyf:0
							})
						}
						let a=t.data.data.goods.price*this.data.ccnum
						wx.request({
							url:getApp().globalData.http+'action=kyQuan&uid='+e.data.uid+'&qtype=1&price='+a+'&goodids='+t.data.data.goods.goods_id,
							success: (e) => {
								console.log(e)
								this.setData({
									list:e.data.data
								})
							}
						})
						console.log(t.data.data.Fee)
						if(t.data.data.addr==null){
							this.setData({
								logs: t.data.data,
								pd:0,
								uid:e.data.uid,
							})
						}else{
							
							this.setData({
								logs: t.data.data,
								pd:1,
								uid:e.data.uid
							})
						}
						
					}
				})
			}
		})
	},
	onShow(){
		this.yunxin()
	},
	none(e) {
	this.setData({
		state:e.currentTarget.dataset.id,
	})
	},
	index(e){
		this.setData({
			itm:e.detail.value
		})
		if(e.detail.value=="1"){
			this.setData({
				yunfei:this.data.logs.Fee,
			}) 
		}else{
			this.setData({
				yunfei:0,
			})
		}
		console.log(e)
	},
	xz(){
		if(this.data.value[1]!='请选择门店'){
			this.setData({
						state:1,
						sure:this.data.itm
					})
		}else{
			if(this.data.itm!=0){
				wx.showToast({
					icon:"none",
					title:'请选择自售门店'
				})
			}else{
				this.setData({
					state:1
				})
			}
		}
	},
	slit(e){
		this.setData({
			lit:e.detail.value
		})
	},
	deal(){
		if(this.data.pd==1){
			let a=0
			if(this.data.logs.goods.remark!=''&&this.data.logs.goods.remark!=undefined){
				a=this.data.logs.goods.remark
			}
			console.log(this.data.jifen)
			wx.request({
				url:getApp().globalData.http2+'action=buyNowJS&userid='+this.data.uid+
				'&goodsid='+this.data.num.name+'&remark='+this.data.lit+'&addrid='
				+this.data.add.ADDR_ID+'&spid='+a+'&pnum='+this.data.num.num+
				'&psType='+this.data.sure+'&shopID='+this.data.value[0]+'&qid='+this.data.qid+'&beanValue='+this.data.jifen,
				success: (e) => {
					console.log(e)
					wx.navigateTo({
						url:'../Vip/deal/deal?orderCode='+e.data.data.orderCode+'&id='+e.data.data.ID+
						"&totalprice="+e.data.data.totalprice+"&Zsprice="+e.data.data.Zsprice
					})
				}
			})
		}else{
			wx.showToast({
				icon:'none',
				title:'请添加地址'
			})
		}
	},
	moon(){
		if(this.data.list.length>0){
			var listData = JSON.stringify(this.data.list)
			wx.navigateTo({
				url:'quan/quan?data='+listData
			})
		}else{
			wx.showToast({
				icon:'none',
				title:'暂无可用优惠券'
			})
		}
	}
})


